package logic

import (
	"context"
	"fmt"
	"jd-mall/jd/models"

	"jd-mall/jd/internal/svc"
	"jd-mall/jd/jd"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopAddLogic) ShopAdd(in *jd.ShopAddRequest) (*jd.ShopAddResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var s models.Shop
	if err = s.GetShop(); err != nil {
		logx.Error("商品不存在")
		return nil, err
	}
	shop := models.Shop{
		Title:     s.Title,
		Price:     s.Price,
		Num:       s.Num,
		Image:     s.Image,
		Status:    1,
		ConStatus: 1,
	}
	fmt.Println(shop)
	if err = s.CreateShop(); err != nil {
		logx.Error("添加失败")
		return nil, err
	}
	return &jd.ShopAddResponse{
		ShopId: int64(s.ID),
	}, nil
}
